package com.ruoyi.stuinfo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.stuinfo.domain.StudentRewards;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.stuinfo.domain.stupun;
import com.ruoyi.stuinfo.service.IstupunService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 违规记录Controller
 *
 * @author zc
 * @date 2025-05-16
 */
@RestController
@RequestMapping("/stuinfo/stupun")
public class stupunController extends BaseController
{
    @Autowired
    private IstupunService stupunService;

    /**
     * 查询违规记录列表
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:stupun:list')")
    @GetMapping("/list")
    public TableDataInfo list(stupun stupun)
    {

        String teacherId = getUsername();
        if("admin".equals(teacherId))
        {
            //管理员
            startPage();
            List<stupun> list = stupunService.selectstupunList(stupun);
            return getDataTable(list);
        }
        else
        {
            //学生
            startPage();
            List<stupun> list = stupunService.selectstupunList_student(teacherId);
            return getDataTable(list);
        }

    }

    /**
     * 导出违规记录列表
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:stupun:export')")
    @Log(title = "违规记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, stupun stupun)
    {
        String teacherId = getUsername();
        if("admin".equals(teacherId))
        {
            //管理员
            List<stupun> list = stupunService.selectstupunList(stupun);
            ExcelUtil<stupun> util = new ExcelUtil<stupun>(stupun.class);
            util.exportExcel(response, list, "违规记录数据");
        }
        else
        {
            //学生
            List<stupun> list = stupunService.selectstupunList_student(teacherId);
            ExcelUtil<stupun> util = new ExcelUtil<stupun>(stupun.class);
            util.exportExcel(response, list, "违规记录数据");
        }

    }

    /**
     * 获取违规记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:stupun:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(stupunService.selectstupunByRecordId(recordId));
    }

    /**
     * 新增违规记录
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:stupun:add')")
    @Log(title = "违规记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody stupun stupun)
    {
        return toAjax(stupunService.insertstupun(stupun));
    }

    /**
     * 修改违规记录
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:stupun:edit')")
    @Log(title = "违规记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody stupun stupun)
    {
        return toAjax(stupunService.updatestupun(stupun));
    }

    /**
     * 删除违规记录
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:stupun:remove')")
    @Log(title = "违规记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(stupunService.deletestupunByRecordIds(recordIds));
    }
}
